package com.lovo.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.sys.bean.UserBean;
import com.lovo.sys.mapper.IUserMapper;
import com.lovo.sys.service.IUserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper userMapper;

    @Override
    public IPage<UserBean> findByConsumption(int pageNO) {
        return userMapper.findByConsumption(new Page<>(pageNO, 2), pageNO);
    }

    @Override
    public UserBean findById(int userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public void updateFrozenState(String userName, int status) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("u_userName", userName);
        UserBean userBean = userMapper.selectOne(qw);
        userBean.setFrozenState(status);
        userMapper.updateById(userBean);
    }

    @Override
    public void addUser(UserBean user) {
        userMapper.insert(user);
    }


}
